package test.lu.materidesign;

import android.animation.TypeEvaluator;
import android.util.Log;

/**
 * Created by Administrator on 2016/10/27 0027.
 */
public class PathEvaluator implements TypeEvaluator<PathPoint> {
    @Override
    public PathPoint evaluate(float t, PathPoint p0, PathPoint p1) {
        Log.e("luchao", "evaluate: " + p1.getType());
        PathPoint p = new PathPoint();
        switch(p1.getType()){
            case PathPoint.PP_MOVETO:
                p.x = p1.x;
                p.y = p1.y;
                break;
            case PathPoint.PP_LINETO:
                p.x = p0.endX + t * (p1.endX - p0.endX);
                p.y = p0.endY + t * (p1.endY - p0.endY);
                break;
            case PathPoint.PP_QUADTO:
                p.x = (float) (Math.pow((1 - t), 2) * p0.endX + 2 * t * (1 - t) * p1.controlX1 + Math.pow(t, 2) * p1.endX);
                p.y = (float) (Math.pow((1 - t), 2) * p0.endY + 2 * t * (1 - t) * p1.controlY1 + Math.pow(t, 2) * p1.endY);

                break;
            case PathPoint.PP_CUBICTO:
                p.x = (float) (p0.endX * Math.pow((1 - t), 3) + 3 * p1.controlX1 * t * Math.pow((1 - t), 2) + 3 * p1.controlX2 * (1 - t) * Math.pow(t, 2) + p1.endX * Math.pow(t, 3));
                p.y = (float) (p0.endY * Math.pow((1 - t), 3) + 3 * p1.controlY1 * t * Math.pow((1 - t), 2) + 3 * p1.controlY2 * (1 - t) * Math.pow(t, 2) + p1.endY * Math.pow(t, 3));

                break;
        }
        return p;
    }
}
